#include "epollServer.hpp"
#include <string>
#include <cstring>
#include <cstdlib>
#include <thread>
#include <pthread.h>
#include <bits/errno.h>
#include "Accerper.hpp"
int main(int argc,char* argv[])
{
    if(argc!=2)
    {
        std::cout<<"Usage:./select_server port"<<std::endl;
        return 1;
    }
    int port = atoi(argv[1]);
    //检测port合法性
    if(port>65535)
    {
        std::cout<<"port is invalid"<<std::endl;
        return 1;
    }
    std::unique_ptr<Socket> ListenSocket(new TcpSocket);
    std::unique_ptr<EpollServer> svr(new EpollServer);

    ListenSocket->BuildListenSocket(port,Net_TcpSocket::default_backlog);

    ns_Util::SetNonBlock(ListenSocket->GetSockfd());

    svr->AddConnection(ConnectionMaker::BuildListenConnection(ListenSocket->GetSockfd(),svr.get(),EPOLLIN | EPOLLERR | EPOLLOUT|EPOLLHUP,ConnectionAccepter::Accepter));
    svr->WorkLoop();
    return 0;
}